package part1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {

    private Socket clientSocket;

    int serverPort = 1025;
    String serverIP = "10.196.113.219";

    public Client(String serverIP, int serverPort) {
	// Ouvrir une solcket client
	try {
	    clientSocket = new Socket(serverIP, serverPort);
	    if (clientSocket.isConnected()) {
		lireClavier();
	    }
	} catch (IOException e) {
	    System.out.println(e);
	}
    }

    public void lireClavier() {
	try {
	    System.out.println("Entrez un message");
	    BufferedReader in = new BufferedReader(new InputStreamReader(
		    System.in));
	    String str = "";

	    str = in.readLine();

	    OutputStream out = clientSocket.getOutputStream();
	    out.write(str.getBytes());
	} catch (IOException e) {
	    System.out.println("Erreur lors de la lecture du clavier");
	}

    }

    public void fermeSocketClient() {
	// Fermer le socket
	try {

	    clientSocket.close(); // Close the socket and its streams
	} catch (IOException e) {
	    System.out.println(e);
	}
    }
}
